package com.atguigu.yygh.task.service;

import com.atguigu.yygh.rabbit.RabbitService;
import com.atguigu.yygh.rabbit.constant.MqConst;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component
@EnableScheduling  //开启定时任务
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    //@Scheduled(cron = "0 0 20 * * ?")
    @Scheduled(cron = "0/50 * * * * *")
    public void noticePatient(){
        System.out.println("每天晚上8点发送mq消息通知Order服务发短信提醒患者就医");
        // 获取现在时间+1天的日期
        DateTime dateTime = new DateTime().plusDays(1);
        String dateString = dateTime.toString("yyyy-MM-dd");

        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_8,dateString);
    }
}
